function bindEvent() {
  $(fo('root')).on("change", function(){
    onRootChange();
  });
}

function onRootChange() {
  var text = $(fo('root')).find("option:selected").text();
  if (text.indexOf('╋') != -1) {
    myMsg('请选择第三级节点', 'error');
    return;
  }
  text = text.substring(text.indexOf('├ ') + 2);
  $(fo('check_dtl_sal')).val(text);
  $(fo('root_check_dtl_sal')).val(fo('root').value);
  // $(fo('root_check_dtl_sal')).select2('val', [fo('root').value]);

  var params = {
    code: $(fo('root')).val(),
  }
  ajaxPost('/basicdata/getParentNode', params).then((res) => {
    console.log(res);
    var data = res.data;

    $(fo('check_dtl')).val(data.name);
    $(fo('root_check_dtl')).val(data.code);
    // $(fo('root_check_dtl')).select2('val', [data.code]);

    var params = {
      code: data.code,
    }
    ajaxPost('/basicdata/getParentNode', params).then((res) => {
      var data = res.data;
      $(fo('check_item')).val(data.name);
      $(fo('root_check_item')).val(data.code);
      // $(fo('root_check_item')).select2('val', [data.code]);
    });
  });
}

function getRootCode(treeNodeCode) {
  var params = {code: treeNodeCode};
  ajaxPost('/basicdata/getNode', params).then((res) => {
    var data = res.data;
    $(fo('root')).select2('val', [data.metaData]);
    onRootChange();
  });
}

function onDrawerLoaded_zj_kpi(data) {
  console.log('onDrawerLoaded_zj_kpi', data);
  bindEvent();
  getRootCode(data.treeNodeCode);
}